package ca.llsutherland.squash.persistence;

import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import ca.llsutherland.squash.configuration.DatabaseConnectionInterface;

public class ContainerDatabaseConnection extends AbstractDatabaseConnection {

    private static DatabaseConnectionInterface instance = new ContainerDatabaseConnection();
    private Context initContext;
    private Context envContext;
    private DataSource ds;

    public DatabaseConnectionInterface getInstance() {
        return instance ;
    }

    public void initializeConnection() throws SQLException, NamingException {
        if (getCurrentConnection() == null) {
            this.initContext = new InitialContext();
            this.envContext = (Context) this.initContext.lookup("java:/comp/env");
            this.ds = (DataSource) this.envContext.lookup("jdbc/mydb");
            setCurrentConnection(this.ds.getConnection());
        }
    }

    @Override
    public void registerNewDomainObject(Long id, String tableName) {
        //never do anything here
    }

    @Override
    public void deleteNewDomainObjects() {
        //never do anything here
    }

    @Override
    public void removeDomainObject(Long idToRemove) {
        //never do anything here
    }
     
}
